/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.bme.j2ee.v37zen.beans;

import hu.bme.j2ee.v37zen.entities.Dial;
import hu.bme.j2ee.v37zen.entities.User;
import java.util.ArrayList;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Kiss Dániel
 */
@Stateless
@LocalBean
public class AddDialBean {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    @PersistenceContext
    EntityManager em;
    
    
    public void addDial(User user, Dial dial){
        if(user == null){
            return;
        }
        if(user.getDials() == null){
            user.setDials(new ArrayList<Dial>());
        }
        user.getDials().add(dial);
        em.persist(dial);
    }

}
